package com.hnas.account.service.mapper;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.BeanUtils;

import com.hnas.account.orm.Account;
import com.hnas.account.service.dto.DTOAccount;
import com.hnas.account.util.AccountConstant;
import com.hnas.core.mapper.Mapper;
import com.hnas.core.util.StringUtil;

public class AccountMapper extends Mapper<DTOAccount, Account> {

	private static AccountMapper mapper;
	private AccountMapper(){
		super(DTOAccount.class,Account.class);
	}
	public static AccountMapper getInstance(){
		if(mapper == null){
			mapper = new AccountMapper();
		}
		return mapper;
	}
	public DTOAccount mapToValue(Account vo){
		if(vo == null) return null;
		DTOAccount dto = new DTOAccount();
		BeanUtils.copyProperties(vo, dto);
		if(StringUtil.isNotEmpty(dto.getLoginType())){
			dto.setLoginTypeStr(AccountConstant.getLoginTypeValue(dto.getLoginType()));
		}
		if(StringUtil.isNotEmpty(dto.getAppType())){
			dto.setAppTypeStr(AccountConstant.getAppTypeValue(dto.getAppType()));
		}
		
		if(StringUtil.isNotEmpty(dto.getValid())){
			dto.setValidStr(AccountConstant.getValidValue(dto.getValid()));
		}
		return dto;
	}
	public List<DTOAccount> mapToValue(List<Account> list){
		if(list == null) return null;
		List<DTOAccount> dtoList = new ArrayList<DTOAccount>();
		for(Account vo : list){
			dtoList.add(mapToValue(vo));
		}
		return dtoList;
	}
	
}
